package xyz.quanguanjia.masterboy;

import android.text.TextUtils;

import java.util.HashMap;
import java.util.List;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import xyz.quanguanjia.masterboy.model.SaveComment;
import xyz.quanguanjia.masterboy.net.ApiService;

public class ServiceMedicator {

    private ApiService mService;

    private ServiceMedicator() {
    }

    public ServiceMedicator(ApiService service) {
        this.mService = service;
    }

    /*
        登录
        */
    public Call<MBDModelResponse> doLoginService(HashMap<String, String> params) {

        MBDLoginConfirmRequestModel requestModel = new MBDLoginConfirmRequestModel();
        String phoneNumber = params.get("phoneNumber");
        String smsCode = params.get("verificationCode");

        requestModel.phoneNumber = phoneNumber;
        requestModel.verificationCode = smsCode;

        Call<MBDModelResponse> callb = this.mService.userLogin(requestModel); // 传入路径参数
        return callb;

    }

    /*
    获取验证码
    */
    public Call<MBDModelResponse> doVerificationCode(HashMap<String, String> params) {

        MBDLoginSMSRequestModel requestModel = new MBDLoginSMSRequestModel();
        String phoneNumber = params.get("phoneNumber");
        requestModel.phoneNumber = phoneNumber;

        Call<MBDModelResponse> callb = this.mService.verificationCode(requestModel); // 传入路径参数
        return callb;
    }

    /*
     * 获取用户信息
     * */
    public Call<MBDModelResponse> doGetUserInfo(HashMap<String, String> params) {

        Call<MBDModelResponse> callb = this.mService.userGetInfo(); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doHomeList(HashMap<String, String> params) {
        if (params.containsKey("keyword")) {
            return this.mService.listPage(params.get("pageNum"), params.get("keyword"));
        } else {
            return this.mService.listPage(params.get("pageNum"), "");
        }
    }

    public Call<MBDModelResponse> doUserMessageList(HashMap<String, String> params) {

        Call<MBDModelResponse> callb = this.mService.userMessageListPage(params.get("pageNum")); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doPostList(HashMap<String, String> params) {

        Call<MBDModelResponse> callb = this.mService.userGroupListPage("1"); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doGroupCommentsList(HashMap<String, String> params) {
        String groupId = params.get("groupId");

        Call<MBDModelResponse> callb = this.mService.groupCommentList(groupId); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doGroupCommentSave(HashMap map) {
        Call<MBDModelResponse> callb = this.mService.groupCommentSave(map); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doGroupLike(HashMap map) {
        Call<MBDModelResponse> callb = this.mService.groupLike(map); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doGroupCommentLike(HashMap map) {
        Call<MBDModelResponse> callb = this.mService.groupCommentLike(map); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doGroupCommentReplyLike(HashMap map) {
        Call<MBDModelResponse> callb = this.mService.groupCommentReplyLike(map); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doGroupCommentReplySave(HashMap map) {
        Call<MBDModelResponse> callb = this.mService.groupCommentReplySave(map); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> detailPage(HashMap<String, String> params) {

        String groupId = params.get("groupId");
        Call<MBDModelResponse> callb = this.mService.detailPage(groupId); // 传入路径参数
        return callb;
    }


    /*
     * 删除用户
     * */
    public Call<MBDModelResponse> doUserWriteoff(HashMap<String, String> params) {

        Call<MBDModelResponse> callb = this.mService.userWriteoff(); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doUpdateUserInfo(HashMap<String, String> params) {
        MBDUpdateUserInfoRequestModel requestModel = new MBDUpdateUserInfoRequestModel();
        String userId = params.get("userId");
        assert !TextUtils.isEmpty(userId);
        if (params.containsKey("avatarUrl")) {
            String avatarUrl = params.get("avatarUrl");
            requestModel.avatarUrl = avatarUrl;
        }
        if (params.containsKey("realName")) {
            String realName = params.get("realName");
            requestModel.realName = realName;
        }
        if (params.containsKey("weChatNumber")) {
            String weChatNumber = params.get("weChatNumber");
            requestModel.weChatNumber = weChatNumber;
        }
        if (params.containsKey("deviceToken")) {
            String deviceToken = params.get("deviceToken");
            requestModel.deviceToken = deviceToken;
        }
        requestModel.userId = userId;
        Call<MBDModelResponse> callb = this.mService.updateUserInfo(requestModel); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doSaveGroupInfo(HashMap<String, String> params) {

        MBDGroupInfoRequestModel requestModel = new MBDGroupInfoRequestModel();

        requestModel.groupName = params.get("groupName");
        requestModel.groupManager = params.get("groupManager");
        requestModel.groupDesc = params.get("groupDesc");
        requestModel.groupLogo = params.get("groupLogo");
        requestModel.groupType = params.get("groupType");

        Call<MBDModelResponse> callb = this.mService.saveGroupInfo(requestModel); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doUploadFile(HashMap<String, RequestBody> params, List<MultipartBody.Part> parts) {

        Call<MBDModelResponse> callb = this.mService.uploadAvatar(parts); // 传入路径参数
        return callb;
    }

    public Call<MBDModelResponse> doIntegrateDetail(HashMap<String, String> params) {
        String pageNum = params.get("pageNum");

        // 调用正确的 Retrofit 接口方法
        return this.mService.integrateDetail(pageNum);
    }

    public Call<MBDModelResponse> apiServiceWith(ServiceType type, HashMap<String, String> params) {

        switch (type) {
            case SERVICE_LOGIN: {
                return this.doLoginService(params);
            }
            case SERVICE_VERIFICATIONCODE: {
                return this.doVerificationCode(params);
            }
            case SERVICE_USER_GET_INFO: {
                return this.doGetUserInfo(params);
            }
            case SERVICE_GROUP_GET_INFO: {
                return this.detailPage(params);
            }
            case SERVICE_USER_UPDATE_INFO: {
                return this.doUpdateUserInfo(params);
            }
            case SERVICE_USER_WRITEOFF: {
                return this.doUserWriteoff(params);
            }
            case SERVICE_HOME_LIST: {
                return this.doHomeList(params);
            }
            case SERVICE_MESSAGE_LIST: {
                return this.doUserMessageList(params);
            }
            case SERVICE_GROUP_INFO_SAVE: {
                return this.doSaveGroupInfo(params);
            }
            case SERVICE_GROUP_COMMENT_LIST: {
                return this.doGroupCommentsList(params);
            }
            case SERVICE_GROUP_COMMENT_SAVE: {
                return this.doGroupCommentSave(params);
            }
            case SERVICE_GROUP_LIKE: {
                return this.doGroupLike(params);
            }
            case SERVICE_GROUP_COMMENT_LIKE: {
                return this.doGroupCommentLike(params);
            }
            case SERVICE_GROUP_COMMENT_REPLY_LIKE: {
                return this.doGroupCommentReplyLike(params);
            }
            case SERVICE_GROUP_COMMENT_REPLY_SAVE: {
                return this.doGroupCommentReplySave(params);
            }
            case SERVICE_POST_LIST: {
                return this.doPostList(params);
            }
            case SERVICE_INTEGRATE_DETAIL:
                return doIntegrateDetail(params);
            default: {

            }
            break;
        }

        return null;
    }


}
